package com.fairplay.test.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.fairplay.test.R2;
import com.frameworkc.ffmpeg.FFmpegPlayer;
import com.gwm.annotation.layout.Layout;
import com.gwm.annotation.router.ARouter;
import com.jetpackframework.Application;
import com.jetpackframework.base.BaseActivity;
import com.jetpackframework.routerview.RouterViewLoader;
import com.test.layout.activity_main;

@ARouter("test/main")
@Layout(R2.layout.activity_main)
public class MainActivity extends BaseActivity<activity_main> implements SurfaceHolder.Callback {
    FFmpegPlayer player;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        player = new FFmpegPlayer();
        player.setDataSource("/sdcard/aaa.avi");
        mBinding.surface.getHolder().addCallback(this);
        player.setOnErrorListener(err -> Log.e("FFmpegPlayer","FFmpegPlayer error: "+err));
        player.setOnPrepareListener(() -> {
            Log.e("FFmpegPlayer","FFmpegPlayer onPrepared");
            player.start();
        });
        player.prepare();
        arouterActivity("test://${packageName}/test/firend");
    }

    @Override
    public void surfaceCreated(@NonNull SurfaceHolder holder) {

    }

    @Override
    public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {
        player.setSurface(holder.getSurface());
    }

    @Override
    public void surfaceDestroyed(@NonNull SurfaceHolder holder) {

    }
}
